<!DOCTYPE html>
<html>

    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <title>登录</title>
    <link href="/education/css/layui.css" rel="stylesheet" media="screen"/>
<body style="background-color: #2a2f3a;">
    <div style="margin: 288px auto auto auto;  width: 450px;">
        <form class="layui-form" method="post" id="loginForm">
            <div class="layui-form-item" style="margin-top: 10px;">
                    <label class="layui-form-label" style="color: #ffffff;">用户名</label>
                <div class="layui-input-inline">
                    <input id="username" type="text" name="username" lay-verify="required" autocomplete="off" placeholder="请输用户名" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" style="color: #ffffff;">密码</label>
                <div class="layui-input-inline">
                    <input id="password" type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input"/>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button id="loginBtn" type="button" class="layui-btn">登录</button>
                    <button type="reset" class="layui-btn layui-btn-primary">清空</button>
                </div>
            </div>
        </form>
    </div>
<script src="/education/js/sha256.js"></script>
<script src="/education/js/jquery.min.js"></script>

<script >
$("#loginBtn").click(function() {
    var userName = $.trim($("#username").val());
    var password = $.trim($("#password").val());
    //账号为空提示用户
    if(userName == ""){
        alert("用户名不能为空！");
        return false;
    }
    //密码为空提示用户
    if(password == ""){
        alert("密码不能为空！");
        return false;
    }

    //密码加密
    password = sha256_digest(password);
    var params = {"userName":userName,"password":password};
    $.ajax({
        method:"POST",
        url:"/education/api/login/authLogin",
        contentType: 'application/json',
        data:JSON.stringify(params),
        dataType:'json',
        success:function(rsp){
            if(rsp.returnCode == 0){
                //登录成功 跳转主页面
                window.location.href="/education/html/index.html"
            }else{
                alert("登录失败！");
            }
        },
        error:function(returnMsg){
            console.log(returnMsg);
        }
    })
});
</script>
</body>
</html>